package com.tucc.hello.leetcode.no1_400.no1_200.no21_40.no26;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1, 2, 2, 3, 3, 4};
        int l = solution.removeDuplicates(nums);
        for(int i = 0;i < l;i ++){
            System.out.print(nums[i] + " ");
        }
        System.out.println();
    }

    public int removeDuplicates(int[] nums) {
        if(nums.length == 0){
            return 0;
        }
        int s = 1;
        int i = 1;
        for(;i < nums.length;i ++){
            if(nums[i] != nums[i - 1]){
                if(i != s){
                    nums[s] = nums[i];
                }
                s ++;
            }
        }
        return s;
    }
}
